﻿Imports System.Collections
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text

Namespace Config
    Public Enum ExceptionReturnMode
        Exception = 1
        ExceptionString
        ErrorCode
        ErrorString
    End Enum
    Public Enum ExceptionAlertType
        None = 1
        WEBUI
        WinUI
    End Enum
    Public Enum ErrorCodeSource
        XML = 1
        DB = 2
    End Enum

    Public Class ExceptionConfig
        Inherits CollectionBase
        Private m_ErrorCodeSource As ErrorCodeSource
        Private m_ConnectionString As String
        Private m_DataTable As String

        Public Property ErrorCodeSource() As ErrorCodeSource
            Get
                Return m_ErrorCodeSource
            End Get
            Set(ByVal value As ErrorCodeSource)
                m_ErrorCodeSource = value
            End Set
        End Property

        Public Property ConnectionString() As String
            Get
                Return m_ConnectionString
            End Get
            Set(ByVal value As String)
                m_ConnectionString = value
            End Set
        End Property

        Public Property DataTable() As String
            Get
                Return m_DataTable
            End Get
            Set(ByVal value As String)
                m_DataTable = value
            End Set
        End Property

        Default Public ReadOnly Property Item(ByVal index As Integer) As ExceptionHandlerConfig
            Get
                Return TryCast(List(index), ExceptionHandlerConfig)
            End Get
        End Property

        Default Public ReadOnly Property Item(ByVal strHandlerName As String) As ExceptionHandlerConfig
            Get
                For Each config As ExceptionHandlerConfig In List
                    If config.Name = strHandlerName Then
                        Return config
                    End If
                Next
                Return Nothing
            End Get
        End Property

        Public Function Add(ByVal value As ExceptionHandlerConfig) As Integer
            Return (List.Add(value))
        End Function

        Public Function IndexOf(ByVal value As ExceptionHandlerConfig) As Integer
            Return (List.IndexOf(value))
        End Function

        Public Sub Insert(ByVal index As Integer, ByVal value As ExceptionHandlerConfig)
            List.Insert(index, value)
        End Sub

        Public Sub Remove(ByVal value As ExceptionHandlerConfig)
            List.Remove(value)
        End Sub

        Public Function Contains(ByVal value As ExceptionHandlerConfig) As Boolean
            Return (List.Contains(value))
        End Function

        Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value As [Object])
            If value.[GetType]() IsNot Type.[GetType]("Tohto.Base.ExceptionPolicy.Config.ExceptionConfig+ExceptionHandlerConfig") Then
                Throw New ArgumentException("値はExceptionHandlerConfigタイプでなければならない。", "value")
            End If
        End Sub

        Protected Overrides Sub OnRemove(ByVal index As Integer, ByVal value As [Object])
            If value.[GetType]() IsNot Type.[GetType]("Tohto.Base.ExceptionPolicy.Config.ExceptionConfig+ExceptionHandlerConfig") Then
                Throw New ArgumentException("値はExceptionHandlerConfigタイプでなければならない。", "value")
            End If
        End Sub

        Protected Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue As [Object], ByVal newValue As [Object])
            If newValue.[GetType]() IsNot Type.[GetType]("Tohto.Base.ExceptionPolicy.Config.ExceptionConfig+ExceptionHandlerConfig") Then
                Throw New ArgumentException("値はExceptionHandlerConfigタイプでなければならない。", "newValue")
            End If
        End Sub

        Protected Overrides Sub OnValidate(ByVal value As [Object])
            If value.[GetType]() IsNot Type.[GetType]("Tohto.Base.ExceptionPolicy.Config.ExceptionConfig+ExceptionHandlerConfig") Then
                Throw New ArgumentException("値はExceptionHandlerConfigタイプでなければならない。")
            End If
        End Sub

        Public Class ExceptionHandlerConfig
            Private m_Name As String
            Private m_Type As String
            Private m_ReturnMode As ExceptionReturnMode
            Private m_AlertType As ExceptionAlertType
            Private m_LogHandlerConfigCollection As LogHandlerConfigCollection

            Public Property Name() As String
                Get
                    Return m_Name
                End Get
                Set(ByVal value As String)
                    m_Name = value
                End Set
            End Property

            Public Property Type() As String
                Get
                    Return m_Type
                End Get
                Set(ByVal value As String)
                    m_Type = value
                End Set
            End Property

            Public Property ReturnMode() As ExceptionReturnMode
                Get
                    Return m_ReturnMode
                End Get
                Set(ByVal value As ExceptionReturnMode)
                    m_ReturnMode = value
                End Set
            End Property

            Public Property AlertType() As ExceptionAlertType
                Get
                    Return m_AlertType
                End Get
                Set(ByVal value As ExceptionAlertType)
                    m_AlertType = value
                End Set
            End Property

            Public Property LogConfigColletion() As LogHandlerConfigCollection
                Get
                    Return m_LogHandlerConfigCollection
                End Get
                Set(ByVal value As LogHandlerConfigCollection)
                    m_LogHandlerConfigCollection = value
                End Set
            End Property

        End Class

        Public Class LogHandlerConfig
            Private m_Type As String
            Private m_ConnectionString As String
            Private m_DataTable As String

            Public Property Type() As String
                Get
                    Return m_Type
                End Get
                Set(ByVal value As String)
                    m_Type = value
                End Set
            End Property

            Public Property ConnectionString() As String
                Get
                    Return m_ConnectionString
                End Get
                Set(ByVal value As String)
                    m_ConnectionString = value
                End Set
            End Property

            Public Property DataTable() As String
                Get
                    Return m_DataTable
                End Get
                Set(ByVal value As String)
                    m_DataTable = value
                End Set
            End Property
        End Class

        Public Class LogHandlerConfigCollection
            Inherits CollectionBase

            Default Public ReadOnly Property Item(ByVal index As Integer) As LogHandlerConfig
                Get
                    Return TryCast(List(index), LogHandlerConfig)
                End Get
            End Property

            Public Function Add(ByVal value As LogHandlerConfig) As Integer
                Return (List.Add(value))
            End Function

            Public Function IndexOf(ByVal value As LogHandlerConfig) As Integer
                Return (List.IndexOf(value))
            End Function

            Public Sub Insert(ByVal index As Integer, ByVal value As LogHandlerConfig)
                List.Insert(index, value)
            End Sub

            Public Sub Remove(ByVal value As LogHandlerConfig)
                List.Remove(value)
            End Sub

            Public Function Contains(ByVal value As LogHandlerConfig) As Boolean
                Return (List.Contains(value))
            End Function

            Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value As [Object])
                If value.[GetType]() IsNot Type.[GetType]("Tohto.Base.ExceptionPolicy.Config.ExceptionConfig+LogHandlerConfig") Then
                    Throw New ArgumentException("値はLogHandlerConfigタイプでなければならない。", "value")
                End If
            End Sub

            Protected Overrides Sub OnRemove(ByVal index As Integer, ByVal value As [Object])
                If value.[GetType]() IsNot Type.[GetType]("Tohto.Base.ExceptionPolicy.Config.ExceptionConfig+LogHandlerConfig") Then
                    Throw New ArgumentException("値はLogHandlerConfigタイプでなければならない。", "value")
                End If
            End Sub

            Protected Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue As [Object], ByVal newValue As [Object])
                If newValue.[GetType]() IsNot Type.[GetType]("Tohto.Base.ExceptionPolicy.Config.ExceptionConfig+LogHandlerConfig") Then
                    Throw New ArgumentException("値はLogHandlerConfigタイプでなければならない。", "newValue")
                End If
            End Sub

            Protected Overrides Sub OnValidate(ByVal value As [Object])
                If value.[GetType]() IsNot Type.[GetType]("Tohto.Base.ExceptionPolicy.Config.ExceptionConfig+LogHandlerConfig") Then
                    Throw New ArgumentException("値はLogHandlerConfigタイプでなければならない。")
                End If
            End Sub
        End Class
    End Class
End Namespace
